<?php 
  class Mod_teacher extends Model{
      function Mod_teacher(){
          parent::model();
          
      }
      function index(){
          
          
      }
      // =================adding data into tbl_teacher===================//
      
      function add(){
          
             $data = array(
                 'tea_name' => $this->input->post('txtTeach_n'),
                'stu_number' => $this->input->post('txtstu_n'),
                'tea_status'=>1,
                'class_time' => $this->input->post('txtclas_time'),
                'date'=>$this->input->post('txtdate'),
                 'tea_description'=>$this->input->post('txtarea')
                     
                 );
               return $this->db->insert('tbl_teacher',$data);
			
      }
      
      //====================this is function select from view=================//
      
      function select_teacher(){
          return $this->db->query('SELECT *FROM tbl_teacher');
      }
      
      //========================this is pagination===========================//
      
       function get_page_limit($start_row, $per_page) {
        $query = "SELECT *FROM tbl_teacher limit $start_row,$per_page";
        $result = $this->db->query($query);
        return $result;
    }
      //======================select edit teacher========================//
      
      function selectedit(){
          $id=$this->uri->segment('3');
          $this->db->where('tea_id',$id);
          return $this->db->get('tbl_teacher');
          
      }
      
      //=========================check edit=======================//
      
      function checkedit(){
           $data = array(
                 'tea_name' => $this->input->post('txtTeach_n'),
                 'stu_number' => $this->input->post('txtstu_n'),
                 'class_time' => $this->input->post('txtclas_time'),
                 'date'=>$this->input->post('mydate'),
                 'tea_description'=>$this->input->post('txtarea')
                     
                 );
              $id=$this->uri->segment('3');
              $this->db->where('tea_id',$id);
               return $this->db->update('tbl_teacher',$data);
          
      }
      
      //========================delete data from tbl_teacher==========================//
      
      function delete(){
          $id=$this->uri->segment('3');
          $this->db->where('tea_id',$id);
          return $this->db->delete('tbl_teacher');
           
      }
      
      //==========================this is searching teacher name=========================//
      
       function get_teacher($p=null) { // $p is array
        if ($this->input->post($this->dbf->tea_name) && $this->input->post($this->dbf->tea_name) != '')
        $this->db->like($this->dbf->tea_name, $this->input->post($this->dbf->tea_name));
        $this->db->limit($p[0], $p[1]);
        $this->db->where('tea_status',1);
        $this->db->order_by('tea_id','desc');
        return $this->db->get('tbl_teacher');
    }
      
  }